package cn.edu.scau.cmi.yangzhichao.composite.consistent;

import javafx.fxml.FXML;
import javafx.scene.control.TextArea;


public class ConsistentCompositeViewController {
    private static ConsistentComposite root;
    private static String showText="";
    @FXML
    private TextArea textArea;
    @FXML
    private void initialize(){
        root=new ConsistentComposite("root");
        root.addChild(new ConsistentLeaf("LeafA"));
        ConsistentComposite composite=new ConsistentComposite("BranchA");
        composite.addChild(new ConsistentLeaf("LeafB"));
        ConsistentComposite composite1=new ConsistentComposite("BranchB");
        composite1.addChild(new ConsistentLeaf("LeafC"));
        composite.addChild(composite1);
        root.addChild(composite);
    }
    @FXML
    private void handleShow(){
        textArea.setText("");
        showText="";
        root.display(0);
        textArea.setText(showText);
    }
    @FXML
    private void handleAdd(){
        root.addChild(new ConsistentComposite("Branch"));
        root.addChild(new ConsistentLeaf("Leaf"));
        handleShow();
    }
    @FXML
    private void handleDelete(){
        root.deleteChild(root.getChildren().size()-1);
        handleShow();
    }
    @FXML
    private void handleUpdate(){
        root.updateChild(new ConsistentLeaf("updateLeaf"),root.getChildren().size()-1);
        handleShow();
    }
    public static void addToTextView(String string){
        showText+=string;
    }

}
